package com.leetcode.leetcode3;


import java.util.ArrayList;
import java.util.List;

/**
 * 回文链表
 *
 * @author luhd
 * @date 2023-08-23
 */
public class Practice234 {
    /**
     * 给你一个单链表的头节点 head ，请你判断该链表是否为回文链表。如果是，返回 true ；否则，返回 false 。
     * <p>
     * 输入：head = [1,2,2,1]
     * 输出：true
     */
    public static void main(String[] args) {

    }

    public static boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        boolean flag = true;
        for (int i = 0; i < list.size()/2+1; i++) {
            if (!list.get(i).equals(list.get(list.size()-i-1))) {
                flag = false;
            }
        }
        return flag;
    }

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}